import axios from 'axios'
import qs from 'qs'
// axios 配置
axios.defaults.timeout = 20000;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';

const APIURL = "http://api.nbbaijin.com/"; //测试API

//POST传参序列化
axios.interceptors.request.use((config) => {
    if (config.method === 'post') {
        config.data = qs.stringify(config.data);
    }
    return config;
}, (error) => {
    alert('错误的传参')
    return Promise.reject(error);
});
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    return response;
}, function (error) {
    // console.log('接口出错,请检查是否登录')
    location.href='http://m.nbbaijin.com/';
    return Promise.reject(error);
});
export function fetch(url, params) {
    return new Promise((resolve, reject) => {
        if (params == null)
            params = {};
        axios.post(url, params)
            .then(response => {
                resolve(response.data);
                // console.log(response)
            }, err => {
                // errMsg()

            })
            .catch((error) => {
                //reject(error)
            })
    })
}
export default {
    Post(url,params){
        return fetch(APIURL + url, params)
    },
    //上传图片
    UploadURl(params){
        return fetch('http://upfile.nbbaijin.com/UpFile/Base64', params)
    },
    //登录
    Login(params) {
        return fetch(APIURL + 'Member/Login/Login', params)
    },
    //测试
    helloworld (params) {
        return fetch(APIURL + 'TouristExperienceDetail/GetExperienceDetaillList', params)
    },
    //获取登录会员信息
    GetModel (params) {
        return fetch(APIURL + 'Member/Login/GetModel', params)
    },
    //最新报价条数
    NewCount (params) {
        return fetch(APIURL + 'Order/QuoteInfo/NewCount', params)
    },
    //报价设置已读
    SetRead (params) {
        return fetch(APIURL + 'Order/QuoteInfo/SetRead', params)
    },
    //退出登录
    LoginOut (params) {
        return fetch(APIURL + 'Member/Login/LoginOut', params)
    },
    //分页获取分期列表
    OGetListPage (params) {
        return fetch(APIURL + 'Order/StagingDetail/GetList', params)
    },   
    //获取单条保单信息
    GetOneModel (params) {
        return fetch(APIURL + 'Order/PolicyOrder/GetOneModel', params)
    },   
    //banner图
    GetBanner (params) {
        return fetch(APIURL + 'Banner/CarouselBanner/GetListByPage', params)
    },
    //保险类别
    GetSafeList (params) {
        return fetch(APIURL + 'Insurance/InsuranceDetail/GetList', params)
    },
    //添加报价
    AddQuote (params) {
        return fetch(APIURL + 'Order/QuoteInfo/AddQuote', params)
    },
    //获取保险公司
    GetInsuranceList (params) {
        return fetch(APIURL + 'Insurance/InsuranceInfo/GetList', params)
    },
    //分页获取报价列表
    QGetListByPage (params) {
        return fetch(APIURL + 'Order/QuoteInfo/GetListByPage', params)
    },
    //报价删除
    DelQuote (params) {
        return fetch(APIURL + 'Order/QuoteInfo/DelQuote', params)
    },
    //绑定手机
    BindPhone (params) {
        return fetch(APIURL + 'Member/Login/BindPhone', params)
    },
    //修改密码
    ResetLog (params) {
        return fetch(APIURL + 'Member/Login/ResetLog', params)
    },
    //单独获取交强险报价
    OGetListByPage (params) {
        return fetch(APIURL + 'Order/PHQuoteInfo/GetListByPage', params)
    },
    //单独删除交强险报价
    ODelQuote (params) {
        return fetch(APIURL + 'Order/PHQuoteInfo/DelQuote', params)
    },
     //单独交强险已读
    OSetRead (params) {
        return fetch(APIURL + 'Order/PHQuoteInfo/SetRead', params)
    },
    //单独交强险已读
    SendValidation (params) {
        return fetch(APIURL + 'Tool/SysSMS/SendValidation', params)
    },
}